import stuIfm from './ifm.js';


function add0(num) {
  if (num < 10) {
    return '0' + num;
  } else {
    return num;
  }
}


function getTime() {
  let now = new Date();
  let month = now.getMonth() + 1;
  let day = now.getDate();
  let hours = now.getHours();
  let minutes = now.getMinutes();
  let seconds = now.getSeconds();
  return [
    add0(month) + '月' + add0(day) + '日',
    add0(hours) + ':' + add0(minutes) + ':' + add0(seconds)
  ]
}


const main = new Vue({
  el: '#root',
  data: {
    date: null,
    time: null,
    stu: {}
  },
  created() {
    this.setStuIfm();
    this.freshTime();
  },
  methods: {
    setStuIfm() {
      let hash = window.location.hash;
      if (hash.length > 1) {
        let name = hash.substring(1);
        let ifm = stuIfm[name];
        this.stu = ifm;
      }
    },
    freshTime() {    
      setInterval(() => {
        let [date, time] = getTime();
        this.date = date;
        this.time = time;
      }, 1000)
    },
  }
})